package com.itheima.service;

import com.itheima.dao.IStudentDao;
import com.itheima.domain.Student;
import com.itheima.factory.Factory;

import java.util.ArrayList;

public class ImplStudentService implements IStudentService {
    private IStudentDao studentDao = Factory.getStudentDao();

    @Override
    public boolean isExist(String id) {
        ArrayList<Student> students = studentDao.findAllAtudent();
        for (int i = 0; i < students.size(); i++) {
            Student student = students.get(i);
            if (student.getId().equals(id)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public void addStudent(Student student) {
        studentDao.addStudent(student);
    }

    @Override
    public void deleteStudent(String id) {
        studentDao.deleteStudent(id);
    }

    @Override
    public void updateStudent(String id, Student newStu) {
        studentDao.updateStudent(id, newStu);
    }

    @Override
    public ArrayList<Student> findAllStudent() {
        ArrayList<Student> students = studentDao.findAllAtudent();
        return students;
    }

    @Override
    public ArrayList<Student> findStuByName(String name) {
        ArrayList<Student> stus = studentDao.findStuByName(name);
        return stus;
    }

    @Override
    public Student findStuByphone(String phone) {
        Student stu = studentDao.findStuByPhone(phone);
        return stu;
    }
}
